package Demo;

public class Demo_03 {
    public static void main(String[] args) {
        //1.线程创建：继承Thread类，重写run方法
        MyThread2 myThread2 = new MyThread2();
        //2.线程创建：实现Runnable接口，重写run方法
        MyRunnable2 myRunnable2 = new MyRunnable2();
        Thread thread2 = new Thread(myRunnable2);
        //启动线程
        thread2.start();
        myThread2.start();
    }
}
class MyThread2 extends Thread{
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("hello MyThread ...");
        }
    }
}
class MyRunnable2 implements Runnable{
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("hello MyRunnable...");
        }
    }

}